/**
 * Created by 邵亚楠 on 2018/9/8.
 */
var sessionId = sessionStorage.getItem('sessionId');
//var sessionId = 'oQ_An0pr2htuLDV42lwE1LeRM220'
$(function () {
    getQunshu()
})
function getQunshu() {
    var swiperSlideHtml = '';
    $.ajax({
        url: 'https://www.bjdeshangyuan.com/book/api/detail/showIndex',
        type: 'POST',
        data: {'sessionid':sessionId},
        success: function (r) {
            var bookList = r.data.hotList
            //循环热门推荐
            for (var i = 0; i < bookList.length; i++) {
                var bookId = bookList[i].id;
                var newList = bookList[i]
                var html = ''
                    html +=
                    '<li class="hot" onclick="getHot('+bookId+')">' +
                    '<img src="http://www.bjdeshangyuan.com/book' + newList.img + '" alt=""/>' +
                    '<p>' + newList.name + '</p>' +
                    '</li>'
                $('#ul').append(html)
            }
            //$('.hot').click(function () {
            //    window.location.href = "bookDetail.html?bookId=" + bookId + ""
            //})

            //购买热门
            var shopHot = r.data.buyList
            //console.log(shopHot)

            for (var i = 0; i < shopHot.length; i++) {
                //console.log(shopHot[i].img)
                var shopData = shopHot[i]
                var bookId = shopData.id
                console.log(bookId)
                var html =
                    '<div class="item_book" onclick="getHot1('+bookId+')">' +
                    '<div class="pic">' +
                    '<img src="http://www.bjdeshangyuan.com/book' + shopData.img + '" alt=""/>' +
                    '</div>' +
                    '<div class="book-detail">' +
                    '<p class="book-name">' + shopData.name + '</p>' +
                    '<p class="book-introduce">' + shopData.bookIntroduce + '</p>' +
                    '</div>' +
                    '</div>'
                $('.list-book').append(html)

                //$('.item_book').click(function () {
                //    window.location.href = "bookDetail.html?bookId=" + bookId + ""
                //})
                //轮播图
                swiperSlideHtml += '<div class="swiper-slide">' + '<img src="http://www.bjdeshangyuan.com/book' + shopData.img + '">' + '</div>'

                //swiperSlideHtml += '<div class="swiper-slide">Swiper-slide' + i + '</div>'
            }
            $('.swiper-wrapper').html(swiperSlideHtml)
            //初始化轮播图
            var mySwiper = new Swiper('.swiper-container', {
                loop: true,
                autoplay: {
                    delay: 2000,
                },
                observer:true,
                observeParents:true,
                // 如果需要分页器
                pagination: {
                    el: '.swiper-pagination',
                },

            })

        }

    })


}


function getHot(bookId){
        window.location.href = "bookDetail.html?bookId=" + bookId + ""
}

function getHot1(bookId){
    window.location.href = "bookDetail.html?bookId=" + bookId + ""
}






